package com.sto.stoapp.http.request;

import com.sto.stoapp.http.BaseMessage;
import com.sto.stoapp.http.FieldLength;
import com.sto.stoapp.http.MessageType;

import java.nio.ByteBuffer;

public class KailiAftermarketRequest extends BaseMessage implements FieldLength {
	// 参数个数
	private final int PARAM_COUNT = 4;
	private final int COUNT_LENGTH = 4;

	// 网点编号
	private String siteNumber;
	// 工号
	private String jobNumber;
	// 下载的条数
	private String count;

	public KailiAftermarketRequest(String siteNumber, String jobNumber,
			String count) {
		this.siteNumber = siteNumber;
		this.jobNumber = jobNumber;
		this.count = count;
	}

	/**
	 * 凯立售后协议
	 * 
	 * @return
	 */
	public byte[] toByte() {
		int total = MESSAGE_TYPE_LENGTH + SITE_CODE_LENGTH + JOB_NUMBER_LENGTH
				+ COUNT_LENGTH + PARAM_COUNT;
//		StringBuffer buffer = new StringBuffer();
//		buffer.append(plusString("" + total, MESSAGE_BODY_LENGTH) + SEPARATOR);
//
//
//		buffer.append(plusString(siteNumber, SITE_CODE_LENGTH) + SEPARATOR);
//
//		buffer.append(plusString(jobNumber, JOB_NUMBER_LENGTH) + SEPARATOR);
//
//		buffer.append(plusString(count, COUNT_LENGTH) + SEPARATOR);
//
//		return buffer.toString().getBytes();
		
		ByteBuffer sb = ByteBuffer.allocate(total + MESSAGE_BODY_LENGTH + 1);
		sb.put(plusString("" + total, MESSAGE_BODY_LENGTH).getBytes()).put(
				SEPARATOR.getBytes());
		sb.put(plusString("" + MessageType.AFTERMARKET_TYPE,
				MESSAGE_TYPE_LENGTH).getBytes()).put(SEPARATOR.getBytes());
		sb.put(plusString(siteNumber, SITE_CODE_LENGTH).getBytes()).put(
				SEPARATOR.getBytes());
		sb.put(plusString(jobNumber, JOB_NUMBER_LENGTH).getBytes()).put(
				SEPARATOR.getBytes());

		sb.put(plusString(count, COUNT_LENGTH).getBytes()).put(
				SEPARATOR.getBytes());
		return sb.array();
	}
}
